import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

class Solution {
    public static void main(String[] args) {
       String  s = "cbaebabacd";
       String   p =  "abc";
        System.out.println(findAnagrams(s, p));
    }
    public static List<Integer> findAnagrams(String s, String p) {
        List<Integer> list =new ArrayList<>() ;
        char[] ss = s.toCharArray() ;
        char[] pp = p.toCharArray() ;
        int[] pSet = new int[26];
        int[] sum = new int[26];
        int target = pp.length ;
        for(int i = 0 ; i < target ; i ++){
            pSet[pp[i]-'a'] ++ ;
        }
        for(int i = 0,j=0 ; j < ss.length ; j ++){
                sum[ss[j]-'a'] ++ ;
                while(sum[ss[j]-'a'] > pSet[ss[j]-'a']){
                    sum[ss[i++]-'a'] --;
                }
                if(target == j-i+1){
                    list.add(i);
                }
        }
        return list ;

    }
}